<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Html CSS Text Hover Animation Effects</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <ul>
      <li style="--clr: #e6444f">
        <a href="#" class="text">First</a>
      </li>
      <li style="--clr: #f0b024">
        <a href="#" class="text">Attempt</a>
      </li>
      <li style="--clr: #00a492">
        <a href="#" class="text">In</a>
      </li>
      <li style="--clr: #af579b">
        <a href="#" class="text">Learning</a>
      </li>
    </ul>
  </body>
  <script>
    const texts = document.querySelectorAll(".text");
    texts.forEach((text) => {
      const spans = Array.from(text.textContent.trim())
        .map((char) => `<span>${char === "" ? "&nbsp;" : char}</span>`)
        .join("");
      text.innerHTML = spans;

      const spanList = text.querySelectorAll("span");
      spanList.forEach((span, index) => {
        span.addEventListener("mouseover", () => {
          spanList.forEach((s, i) => {
            const distance = Math.abs(index - i);
            const delay = (distance * 0.1).toFixed(1);
            s.style.transitionDelay = `${delay}s`;
          });
        });
      });
    });
  </script>
</html>
